package com.xbongbong.saas.service.impl;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.MessageConstant;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasFormExplainEntity;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.model.PaasFormExplainModel;
import com.xbongbong.paas.service.WorkReportSetService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.util.ExplainUtil;
import com.xbongbong.pro.constant.BusinessConstant;
import com.xbongbong.pro.constant.CommonConstant;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.constant.RangeScreenConstant;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.product.pojo.dto.StockSearchFilterDTO;
import com.xbongbong.pro.weblist.pojo.SpecialListFieldPojo;
import com.xbongbong.pro.weblist.pojo.dto.SaasBaseDTO;
import com.xbongbong.pro.weblist.pojo.vo.SpecialListFilterVO;
import com.xbongbong.pro.workreportset.pojo.WorkReportSetVisibleRange;
import com.xbongbong.saas.enums.ListGroupEnum;
import com.xbongbong.saas.enums.StockSearchConditionEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ContractCompareEnum;
import com.xbongbong.saas.enums.business.CustomerCommunicateEnum;
import com.xbongbong.saas.enums.business.CustomerManagementEnum;
import com.xbongbong.saas.enums.business.SupplierCommunicateEnum;
import com.xbongbong.saas.enums.business.WorkReportDailyEnum;
import com.xbongbong.saas.enums.business.WorkReportFieldEnum;
import com.xbongbong.saas.enums.business.WorkReportTypeEnum;
import com.xbongbong.saas.enums.dictionary.DictionaryEnum;
import com.xbongbong.saas.enums.dictionary.DistanceEnum;
import com.xbongbong.saas.help.FieldAttrHelp;
import com.xbongbong.saas.model.DataDictionaryModel;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import com.xbongbong.saas.service.DictionaryService;
import com.xbongbong.saas.service.SpecialFilterService;
import com.xbongbong.sys.domain.entity.UserEntity;
import com.xbongbong.sys.model.UserModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/2/25 20:00
 * @since v1.0
 */
@Service("specialFilterService")
public class SpecialFilterServiceImpl implements SpecialFilterService {
    @Resource
    private FieldAttrHelp fieldAttrHelp;
    @Resource
    private DictionaryService dictionaryService;
    @Resource
    private WorkReportSetService workReportSetService;
    @Resource
    private UserModel userModel;
    @Resource
    private DataDictionaryModel dataDictionaryModel;
    @Resource
    private PaasFormExplainModel paasFormExplainModel;

    @Override
    public SpecialListFilterVO nearCustomerFilter(SaasBaseDTO saasBaseDTO) throws XbbException {
        PaasFormExplainEntity explainEntity = paasFormExplainModel.getByFormId(saasBaseDTO.getFormId(), saasBaseDTO.getCorpid());
        if (Objects.isNull(explainEntity)) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.FORM_EXPLAIN_NOT_EXIST);
        }
        Map<String, FieldAttrEntity> explainMap = ExplainUtil.getExplainMap(explainEntity.getExplains());
        FieldAttrEntity ownerField = explainMap.get(CustomerManagementEnum.OWNER_ID.getAttr());
        FieldAttrEntity coUserField = explainMap.get(CustomerManagementEnum.COUSERID.getAttr());

        // 设置范围筛选
        SpecialListFieldPojo rangeScreenPojo = new SpecialListFieldPojo();
        rangeScreenPojo.setAttr(RangeScreenConstant.RANGE_SCREEN);
        rangeScreenPojo.setAttrName(FieldTypeEnum.RANGE_SCREEN.getDescription());
        rangeScreenPojo.setFieldType(FieldTypeEnum.RANGE_SCREEN.getType());
        rangeScreenPojo.setMultiple(0);
        rangeScreenPojo.setPlaceholder(I18nMessageUtil.getMessage(RangeScreenConstant.SELECT));
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        if (Objects.nonNull(ownerField)) {
            ItemPoJo ownerPoJo = new ItemPoJo();
            ownerPoJo.setText(ownerField.getAttrName());
            ownerPoJo.setAttr(ownerField.getAttr());
            itemPoJos.add(ownerPoJo);
        }
        if (Objects.nonNull(coUserField)) {
            ItemPoJo coUserPoJo = new ItemPoJo();
            coUserPoJo.setText(coUserField.getAttrName());
            coUserPoJo.setAttr(coUserField.getAttr());
            itemPoJos.add(coUserPoJo);
        }
        rangeScreenPojo.setItems(itemPoJos);

        SpecialListFieldPojo lastConnectTimeFilterPojo = new SpecialListFieldPojo();
        lastConnectTimeFilterPojo.setAttr(CustomerManagementEnum.LAST_CONNECT_TIME.getSaasAttr());
        lastConnectTimeFilterPojo.setAttrName(CustomerManagementEnum.LAST_CONNECT_TIME.getAttrName());
        lastConnectTimeFilterPojo.setFieldType(FieldTypeEnum.DATETIME.getType());
        List<ItemPoJo> customerStatusList = dictionaryService.getArrayList(DictionaryEnum.CUSTOMER_STATUS,saasBaseDTO.getCorpid(), null);
        SpecialListFieldPojo customeStatusFilterPojo = new SpecialListFieldPojo();
        customeStatusFilterPojo.setAttr(CustomerManagementEnum.TYPE.getSaasAttr());
        customeStatusFilterPojo.setAttrName(CustomerManagementEnum.TYPE.getAttrName());
        customeStatusFilterPojo.setFieldType(FieldTypeEnum.COMBO.getType());
        customeStatusFilterPojo.setMultiple(0);
        customeStatusFilterPojo.setPlaceholder(I18nMessageUtil.getMessage(I18nStringConstant.SELECT_CUSTOMER_STATUS));
        customeStatusFilterPojo.setItems(customerStatusList);
        SpecialListFieldPojo distanceFilterPojo = new SpecialListFieldPojo();
        distanceFilterPojo.setAttr("distance");
        distanceFilterPojo.setAttrName(I18nMessageUtil.getMessage(I18nStringConstant.DISTANCE_RANGE));
        distanceFilterPojo.setFieldType(FieldTypeEnum.COMBO.getType());
        distanceFilterPojo.setPlaceholder(I18nMessageUtil.getMessage(I18nStringConstant.SELECT_DISTANCE_RANGE));
        StringBuilder valueBuilder = new StringBuilder();
        for (DistanceEnum distanceEnum : DistanceEnum.getList()){
            StringUtil.stringBuilderAppendSuffix(valueBuilder,",",distanceEnum.getAttr());
        }
        List<ItemPoJo> itemPoJoList = fieldAttrHelp.initItem(valueBuilder.toString());
        distanceFilterPojo.setItems(itemPoJoList);
        SpecialListFieldPojo publicFilterPojo = new SpecialListFieldPojo();
        publicFilterPojo.setAttr(CustomerManagementEnum.IS_PUBLIC.getSaasAttr());
        publicFilterPojo.setAttrName(I18nMessageUtil.getMessage(I18nStringConstant.CHANGE_TO_PUBLIC_CUSTOMER));
        publicFilterPojo.setFieldType(FieldTypeEnum.SWITCH.getType());
        publicFilterPojo.setDefaultValue("0");
        publicFilterPojo.setEditable(1);
        SpecialListFilterVO specialListFilterVO = new SpecialListFilterVO();
        specialListFilterVO.setFieldList(Arrays.asList(rangeScreenPojo, lastConnectTimeFilterPojo,customeStatusFilterPojo,distanceFilterPojo,publicFilterPojo));
        return specialListFilterVO;
    }

    @Override
    public SpecialListFilterVO workReportFilter(SaasBaseDTO saasBaseDTO) throws XbbException{
        SpecialListFilterVO specialListFilterVO = new SpecialListFilterVO();
        SpecialListFieldPojo rangeScreenPojo = new SpecialListFieldPojo();
        rangeScreenPojo.setAttr(RangeScreenConstant.RANGE_SCREEN);
        rangeScreenPojo.setAttrName(FieldTypeEnum.RANGE_SCREEN.getDescription());
        rangeScreenPojo.setFieldType(FieldTypeEnum.RANGE_SCREEN.getType());
        rangeScreenPojo.setMultiple(0);
        rangeScreenPojo.setPlaceholder(I18nMessageUtil.getMessage(RangeScreenConstant.SELECT));
        List<ItemPoJo> itemPoJoLists = new ArrayList<>();
        ItemPoJo item = new ItemPoJo();
        item.setText(I18nMessageUtil.getMessage(I18nStringConstant.SUBMITTER));
        item.setAttr(WorkReportFieldEnum.CREATOR_ID.getAttr());
        itemPoJoLists.add(item);
        rangeScreenPojo.setItems(itemPoJoLists);

        SpecialListFieldPojo creatorPojo = new SpecialListFieldPojo();
        creatorPojo.setAttr(FieldTypeEnum.CREATORID.getAlias());
        creatorPojo.setAttrName(I18nMessageUtil.getMessage(I18nStringConstant.SUBMITTER));
        creatorPojo.setFieldType(FieldTypeEnum.CREATORID.getType());
        creatorPojo.setMultiple(0);
        creatorPojo.setPlaceholder(I18nMessageUtil.getMessage(I18nStringConstant.SELECT_OR_ENTER_SEARCH));
        UserEntity userEntity = userModel.getByKey(saasBaseDTO.getUserId(),saasBaseDTO.getCorpid());
        WorkReportSetVisibleRange workReportSetVisibleRange = workReportSetService.getVisibleRange(userEntity);
        Map<String,Boolean> map = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        map.put(WorkReportTypeEnum.DAILY.getName(),workReportSetVisibleRange.getDayEnable());
        map.put(WorkReportTypeEnum.WEEKLY.getName(),workReportSetVisibleRange.getWeekEnable());
        map.put(WorkReportTypeEnum.MONTHLY.getName(),workReportSetVisibleRange.getMonthEnable());
        List<ItemPoJo> itemPoJoList = new ArrayList<>();
        for (WorkReportTypeEnum workReportTypeEnum : WorkReportTypeEnum.values()){
            boolean enable = map.get(workReportTypeEnum.getName());
            if (enable) {
                ItemPoJo itemPoJo = new ItemPoJo(workReportTypeEnum.getName(),workReportTypeEnum.getType().toString());
                itemPoJoList.add(itemPoJo);
            }
        }
        SpecialListFieldPojo specialListFieldPojo = new SpecialListFieldPojo();
        specialListFieldPojo.setAttr(WorkReportDailyEnum.TYPE.getSaasAttr());
        specialListFieldPojo.setAttrName(WorkReportDailyEnum.TYPE.getAttrName());
        specialListFieldPojo.setFieldType(FieldTypeEnum.COMBO.getType());
        specialListFieldPojo.setMultiple(0);
        specialListFieldPojo.setPlaceholder(I18nMessageUtil.getMessage(I18nStringConstant.SELECT_REPORT_TYPE));
        specialListFieldPojo.setItems(itemPoJoList);
        SpecialListFieldPojo timeFieldPojo = new SpecialListFieldPojo();
        timeFieldPojo.setAttr(WorkReportDailyEnum.REPORT_DATE.getSaasAttr());
        timeFieldPojo.setAttrName(WorkReportDailyEnum.REPORT_DATE.getAttrName());
        timeFieldPojo.setFieldType(FieldTypeEnum.DATETIME.getType());
        timeFieldPojo.setMultiple(0);
        specialListFilterVO.setFieldList(Arrays.asList(rangeScreenPojo, creatorPojo, specialListFieldPojo,timeFieldPojo));
        return specialListFilterVO;
    }

    @Override
    public SpecialListFilterVO stockSearchFilter(StockSearchFilterDTO stockSearchFilterDTO) throws XbbException{
        List<SpecialListFieldPojo> specialListFieldList = new ArrayList<>();
        Integer listGroupId = stockSearchFilterDTO.getListGroupId();
        // 返回vo
        SpecialListFilterVO specialListFilterVO = new SpecialListFilterVO();
        /*if (Objects.equals(stockSearchFilterDTO.getPlatform(), PlatFormEnum.DINGTALK.getValue()) && !Objects.equals(listGroupId, ListGroupEnum.GUARANTEE_SEARCH.getCode())) {
            WarehouseListDTO warehouseListDTO = new WarehouseListDTO();
            BeanUtil.copyProperties(stockSearchFilterDTO, warehouseListDTO);
            // 获取仓库筛选项
            WarehouseListVO warehouseListVO = warehouseService.getManagetWarehouses(warehouseListDTO);
            if (Objects.isNull(warehouseListVO)) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
            }
            List<WarehouseEntityExt> managerWarehouses = warehouseListVO.getWarehouseList();
            Map<String, String> managerWareHouseMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            for (WarehouseEntityExt managetWarehouse : managerWarehouses) {
                // 构造下拉选项items
                Long id = managetWarehouse.getId();
                JSONObject warehouseData = managetWarehouse.getData();
                String warehouseName = saasUpdateHelp.getStringOrDefaultFromFormData(warehouseData, WarehouseEnum.WAREHOUSE_NAME.getAttr(), "");
                managerWareHouseMap.put(String.valueOf(id), warehouseName);
            }
            List<ItemPoJo> warehouseItemPoJoList = InitExplainsHelper.setCombItemByStringMap(managerWareHouseMap);
            if (Objects.equals(listGroupId, ListGroupEnum.WARNING_SEARCH.getCode())) {
                ItemPoJo itemPoJo = new ItemPoJo();
                itemPoJo.setText(I18nMessageUtil.getMessage(I18nStringConstant.ALL_WAREHOUSE));
                itemPoJo.setValue("0");
                itemPoJo.setChecked(false);
                warehouseItemPoJoList.add(0,itemPoJo);
            }
            // 仓库特殊筛选项
            SpecialListFieldPojo warehouseSpecialListFieldPojo = new SpecialListFieldPojo();
            // 构造返回pojo
            warehouseSpecialListFieldPojo.setAttr(ParameterConstant.WAREHOUSE_ID);
            warehouseSpecialListFieldPojo.setAttrName(I18nMessageUtil.getMessage(BusinessConstant.WAREHOUSE));
            warehouseSpecialListFieldPojo.setFieldType(StockSearchConditionEnum.WAREHOUSE_ID.getType());
            // 是否多选 0：否；1：是
            warehouseSpecialListFieldPojo.setMultiple(1);
            warehouseSpecialListFieldPojo.setPlaceholder(I18nMessageUtil.getMessage(BusinessConstant.SELECT_WAREHOUSE));
            warehouseSpecialListFieldPojo.setItems(warehouseItemPoJoList);
            specialListFieldList.add(warehouseSpecialListFieldPojo);
        }*/
        // 其他筛选项
        SpecialListFieldPojo otherSpecialListFieldPojo;
        if (Objects.equals(listGroupId, ListGroupEnum.WARNING_SEARCH.getCode())) {
            // 预警类型特殊筛选项
            otherSpecialListFieldPojo = new SpecialListFieldPojo();
            // 预警类型 1：上限预警 2：下限预警
            Map<String, String> warnTypeMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            warnTypeMap.put("1", I18nMessageUtil.getMessage(BusinessConstant.WARNING_UPPER));
            warnTypeMap.put("2", I18nMessageUtil.getMessage(BusinessConstant.WARNING_LOWER));
            List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByStringMap(warnTypeMap);

            otherSpecialListFieldPojo.setAttr(BusinessConstant.WARNING_TYPE);
            otherSpecialListFieldPojo.setAttrName(I18nMessageUtil.getMessage(BusinessConstant.WARNING_TYPE_CHINESE));
            otherSpecialListFieldPojo.setFieldType(StockSearchConditionEnum.WARNING_TYPE.getType());
            // 是否多选 0：否；1：是
            otherSpecialListFieldPojo.setMultiple(0);
            otherSpecialListFieldPojo.setPlaceholder(I18nMessageUtil.getMessage(BusinessConstant.SELECT_WARNING_TYPE));
            otherSpecialListFieldPojo.setItems(itemPoJoList);
            specialListFieldList.add(otherSpecialListFieldPojo);
        } else if (Objects.equals(listGroupId, ListGroupEnum.GUARANTEE_SEARCH.getCode())) {
//            // 保质期特殊筛选项
//            otherSpecialListFieldPojo = new SpecialListFieldPojo();
//            // 保质期类型 1.已过期 2.15天内过期 3.30天内过期 4.60天内过期 5.60天以上
//            Map<String, String> guaranteeStatusMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
//            List<GuaranteeStatusEnum> allEnum = GuaranteeStatusEnum.getAllEnum();
//            allEnum.forEach(item -> guaranteeStatusMap.put(String.valueOf(item.getCode()), item.getName()));
//            List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByStringMap(guaranteeStatusMap);
//
//            otherSpecialListFieldPojo.setAttr(BusinessConstant.GUARANTEE_STATUS);
//            otherSpecialListFieldPojo.setAttrName(I18nMessageUtil.getMessage(BusinessConstant.GUARANTEE_STATUS_CHINESE));
//            otherSpecialListFieldPojo.setFieldType(StockSearchConditionEnum.GUARANTEE_STATUS.getType());
//            // 是否多选 0：否；1：是
//            otherSpecialListFieldPojo.setMultiple(0);
//            otherSpecialListFieldPojo.setPlaceholder(I18nMessageUtil.getMessage(BusinessConstant.SELECT_GUARANTEE_STATUS));
//            otherSpecialListFieldPojo.setItems(itemPoJoList);
//            specialListFieldList.add(otherSpecialListFieldPojo);

        }
        specialListFilterVO.setFieldList(specialListFieldList);
        return specialListFilterVO;
    }

    @Override
    public SpecialListFilterVO customerCommunicateFilter(SaasBaseDTO saasBaseDTO) throws XbbException {
        PaasFormExplainEntity explainEntity = paasFormExplainModel.getByFormId(saasBaseDTO.getFormId(), saasBaseDTO.getCorpid());
        if (Objects.isNull(explainEntity)) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.FORM_EXPLAIN_NOT_EXIST);
        }
        SpecialListFilterVO specialListFilterVO = new SpecialListFilterVO();
        Map<String, FieldAttrEntity> explainMap = ExplainUtil.getExplainMap(explainEntity.getExplains());
        // 设置范围筛选
        SpecialListFieldPojo rangeScreenPojo = new SpecialListFieldPojo();
        FieldAttrEntity fieldAttrEntity = explainMap.get(CustomerCommunicateEnum.CREATOR_ID.getAttr());
        rangeScreenPojo.setAttr(RangeScreenConstant.RANGE_SCREEN);
        rangeScreenPojo.setAttrName(FieldTypeEnum.RANGE_SCREEN.getDescription());
        rangeScreenPojo.setFieldType(FieldTypeEnum.RANGE_SCREEN.getType());
        rangeScreenPojo.setMultiple(0);
        rangeScreenPojo.setPlaceholder(I18nMessageUtil.getMessage(RangeScreenConstant.SELECT));
        List<ItemPoJo> itemPoJoList = new ArrayList<>();
        ItemPoJo itemPoJo = new ItemPoJo();
        itemPoJo.setText(fieldAttrEntity.getAttrName());
        itemPoJo.setAttr(fieldAttrEntity.getAttr());
        itemPoJoList.add(itemPoJo);
        rangeScreenPojo.setItems(itemPoJoList);
        // 设置跟进方式筛选
        SpecialListFieldPojo communicateTypePojo = new SpecialListFieldPojo();
        communicateTypePojo.setAttr(CustomerCommunicateEnum.TYPE.getAttr());
        communicateTypePojo.setAttrName(CustomerCommunicateEnum.TYPE.getAttrName());
        communicateTypePojo.setFieldType(FieldTypeEnum.COMBO.getType());
        communicateTypePojo.setMultiple(0);
        communicateTypePojo.setPlaceholder(I18nMessageUtil.getMessage(I18nStringConstant.SELECT_OR_ENTER_SEARCH));
        List<ItemPoJo> dictionaryList4Attr = dataDictionaryModel.getDictionaryList4Attr(CustomerCommunicateEnum.TYPE.getSaasAttr(), saasBaseDTO.getCorpid(), saasBaseDTO.getFormId());
        if (!dictionaryList4Attr.isEmpty()) {
            dictionaryList4Attr.removeIf(item -> Objects.isNull(item.getValue()) || StringUtil.isEmpty(item.getValue().toString()));
        }
        communicateTypePojo.setItems(dictionaryList4Attr);
        communicateTypePojo.setFilterable(1);
        SpecialListFieldPojo communicateTimePojo = new SpecialListFieldPojo();
        communicateTimePojo.setAttr(CustomerCommunicateEnum.COMMUNICATE_TIME.getAttr());
        communicateTimePojo.setAttrName(CustomerCommunicateEnum.COMMUNICATE_TIME.getAttrName());
        communicateTimePojo.setFieldType(FieldTypeEnum.DATETIME.getType());
        communicateTimePojo.setMultiple(0);
        SpecialListFieldPojo memoPojo = new SpecialListFieldPojo();
        memoPojo.setAttr(CustomerCommunicateEnum.MEMO.getAttr());
        memoPojo.setAttrName(CustomerCommunicateEnum.MEMO.getAttrName());
        memoPojo.setFieldType(FieldTypeEnum.TEXT.getType());
        memoPojo.setMultiple(0);
        memoPojo.setPlaceholder(I18nMessageUtil.getMessage(I18nStringConstant.KEYWORD_SEARCH));
        SpecialListFieldPojo creatorPojo = new SpecialListFieldPojo();
        creatorPojo.setAttr(CustomerCommunicateEnum.CREATOR_ID.getAttr());
        creatorPojo.setAttrName(CustomerCommunicateEnum.CREATOR_ID.getAttrName());
        creatorPojo.setFieldType(CustomerCommunicateEnum.CREATOR_ID.getFieldType());
        creatorPojo.setMultiple(0);
        creatorPojo.setPlaceholder(I18nMessageUtil.getMessage(I18nStringConstant.SELECT_OR_ENTER_SEARCH));
        specialListFilterVO.setFieldList(Arrays.asList(rangeScreenPojo, creatorPojo, communicateTypePojo, communicateTimePojo, memoPojo));
        return specialListFilterVO;
    }

    @Override
    public SpecialListFilterVO supplierCommunicateFilter(SaasBaseDTO saasBaseDTO) throws XbbException {
        PaasFormExplainEntity explainEntity = paasFormExplainModel.getByBusinessType(saasBaseDTO.getBusinessType(), saasBaseDTO.getCorpid());
        if (Objects.isNull(explainEntity)) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.FORM_EXPLAIN_NOT_EXIST);
        }
        Map<String, FieldAttrEntity> explainMap = ExplainUtil.getExplainMap(explainEntity.getExplains());
        // 设置范围筛选
        SpecialListFieldPojo rangeScreenPojo = new SpecialListFieldPojo();
        FieldAttrEntity fieldAttrEntity = explainMap.get(CustomerCommunicateEnum.CREATOR_ID.getAttr());
        rangeScreenPojo.setAttr(RangeScreenConstant.RANGE_SCREEN);
        rangeScreenPojo.setAttrName(FieldTypeEnum.RANGE_SCREEN.getDescription());
        rangeScreenPojo.setFieldType(FieldTypeEnum.RANGE_SCREEN.getType());
        rangeScreenPojo.setMultiple(0);
        rangeScreenPojo.setPlaceholder(I18nMessageUtil.getMessage(RangeScreenConstant.SELECT));
        List<ItemPoJo> itemPoJoList = new ArrayList<>();
        ItemPoJo itemPoJo = new ItemPoJo();
        itemPoJo.setText(fieldAttrEntity.getAttrName());
        itemPoJo.setAttr(fieldAttrEntity.getAttr());
        itemPoJoList.add(itemPoJo);
        rangeScreenPojo.setItems(itemPoJoList);
        String corpid = saasBaseDTO.getCorpid();
        SpecialListFilterVO specialListFilterVO = new SpecialListFilterVO();
        SpecialListFieldPojo communicateTypePojo = new SpecialListFieldPojo();
        communicateTypePojo.setAttr(SupplierCommunicateEnum.TYPE.getAttr());
        communicateTypePojo.setAttrName(SupplierCommunicateEnum.TYPE.getAttrName());
        communicateTypePojo.setFieldType(FieldTypeEnum.COMBO.getType());
        communicateTypePojo.setMultiple(0);
        communicateTypePojo.setPlaceholder(I18nMessageUtil.getMessage(I18nStringConstant.SELECT_OR_ENTER_SEARCH));
        List<ItemPoJo> dictionaryList4Attr = dataDictionaryModel.getDictionaryList4Attr(SupplierCommunicateEnum.TYPE.getSaasAttr(), corpid, explainEntity.getFormId());
        if (!dictionaryList4Attr.isEmpty()) {
            dictionaryList4Attr.removeIf(item -> Objects.isNull(item.getValue()) || StringUtil.isEmpty(item.getValue().toString()));
        }
        communicateTypePojo.setItems(dictionaryList4Attr);
        communicateTypePojo.setFilterable(1);

        SpecialListFieldPojo communicateTimePojo = new SpecialListFieldPojo();
        communicateTimePojo.setAttr(SupplierCommunicateEnum.COMMUNICATE_TIME.getAttr());
        communicateTimePojo.setAttrName(SupplierCommunicateEnum.COMMUNICATE_TIME.getAttrName());
        communicateTimePojo.setFieldType(FieldTypeEnum.DATETIME.getType());
        communicateTimePojo.setMultiple(0);
        SpecialListFieldPojo memoPojo = new SpecialListFieldPojo();
        memoPojo.setAttr(SupplierCommunicateEnum.MEMO.getAttr());
        memoPojo.setAttrName(SupplierCommunicateEnum.MEMO.getAttrName());
        memoPojo.setFieldType(FieldTypeEnum.TEXT.getType());
        memoPojo.setMultiple(0);
        memoPojo.setPlaceholder(I18nMessageUtil.getMessage(I18nStringConstant.KEYWORD_SEARCH));
        SpecialListFieldPojo creatorPojo = new SpecialListFieldPojo();
        creatorPojo.setAttr(SupplierCommunicateEnum.CREATOR_ID.getAttr());
        creatorPojo.setAttrName(SupplierCommunicateEnum.CREATOR_ID.getAttrName());
        creatorPojo.setFieldType(SupplierCommunicateEnum.CREATOR_ID.getFieldType());
        creatorPojo.setMultiple(0);
        creatorPojo.setPlaceholder(I18nMessageUtil.getMessage(I18nStringConstant.SELECT_OR_ENTER_SEARCH));
        specialListFilterVO.setFieldList(Arrays.asList(rangeScreenPojo, creatorPojo, communicateTypePojo,communicateTimePojo, memoPojo));
        return specialListFilterVO;
    }

    @Override
    public SpecialListFilterVO signInFilter(SaasBaseDTO saasBaseDTO) throws XbbException {
        // 设置范围筛选
        SpecialListFieldPojo rangeScreenPojo = new SpecialListFieldPojo();
        rangeScreenPojo.setAttr(RangeScreenConstant.RANGE_SCREEN);
        rangeScreenPojo.setAttrName(FieldTypeEnum.RANGE_SCREEN.getDescription());
        rangeScreenPojo.setFieldType(FieldTypeEnum.RANGE_SCREEN.getType());
        rangeScreenPojo.setMultiple(0);
        rangeScreenPojo.setPlaceholder(I18nMessageUtil.getMessage(RangeScreenConstant.SELECT));
        List<ItemPoJo> itemPoJoList = new ArrayList<>();
        ItemPoJo itemPoJo = new ItemPoJo();
        itemPoJo.setText(I18nMessageUtil.getMessage(I18nStringConstant.SIGNER));
        itemPoJo.setAttr(FieldTypeEnum.CREATORID.getAlias());
        itemPoJoList.add(itemPoJo);
        rangeScreenPojo.setItems(itemPoJoList);

        SpecialListFilterVO specialListFilterVO = new SpecialListFilterVO();
        SpecialListFieldPojo signPersonPojo = new SpecialListFieldPojo();
        signPersonPojo.setAttr(FieldTypeEnum.CREATORID.getAlias());
        signPersonPojo.setAttrName(I18nMessageUtil.getMessage(I18nStringConstant.SIGNER));
        signPersonPojo.setFieldType(FieldTypeEnum.CREATORID.getType());
        signPersonPojo.setMultiple(0);
        signPersonPojo.setPlaceholder(I18nMessageUtil.getMessage(I18nStringConstant.SELECT_OR_ENTER_SEARCH));
        SpecialListFieldPojo signInPojo = new SpecialListFieldPojo();
        signInPojo.setAttr("signInTime");
        signInPojo.setAttrName(I18nMessageUtil.getMessage(I18nStringConstant.SIGN_TIME));
        signInPojo.setFieldType(FieldTypeEnum.DATETIME.getType());
        signInPojo.setMultiple(0);
        specialListFilterVO.setFieldList(Arrays.asList(rangeScreenPojo, signPersonPojo, signInPojo));
        return specialListFilterVO;
    }

    private SpecialListFieldPojo getCateGorySprcialList() {
        SpecialListFieldPojo categorySpecialListFieldPojo = new SpecialListFieldPojo();
        categorySpecialListFieldPojo.setAttr(StockSearchConditionEnum.CATEGORY_ID.getAlias());
        categorySpecialListFieldPojo.setAttrName(StockSearchConditionEnum.CATEGORY_ID.getMemo());
        categorySpecialListFieldPojo.setFieldType(StockSearchConditionEnum.CATEGORY_ID.getType());
        // 是否多选 0：否；1：是
        categorySpecialListFieldPojo.setMultiple(0);
        categorySpecialListFieldPojo.setPlaceholder(StockSearchConditionEnum.CATEGORY_ID.getPlaceholder());
        return categorySpecialListFieldPojo;
    }

    @Override
    public SpecialListFilterVO productSearchFilter(StockSearchFilterDTO stockSearchFilterDTO) throws XbbException {
        SpecialListFilterVO specialListFilterVO = new SpecialListFilterVO();
        specialListFilterVO.setFieldList(Collections.singletonList(getCateGorySprcialList()));
        return specialListFilterVO;
    }

    @Override
    public SpecialListFilterVO contractCompareFilter(SaasBaseDTO saasBaseDTO) throws XbbException {
        // 设置范围筛选
        SpecialListFieldPojo rangeScreenPojo = new SpecialListFieldPojo();
        rangeScreenPojo.setAttr(ContractCompareEnum.FORM_TYPE.getSaasAttr());
        rangeScreenPojo.setAttrName(ContractCompareEnum.FORM_TYPE.getAttrName());
        rangeScreenPojo.setFieldType(FieldTypeEnum.COMBO.getType());
        rangeScreenPojo.setMultiple(0);
        rangeScreenPojo.setPlaceholder(I18nMessageUtil.getMessage(RangeScreenConstant.SELECT));
        List<ItemPoJo> itemPoJoList = new ArrayList<>();
        ItemPoJo itemPoJo = new ItemPoJo();
        itemPoJo.setText(I18nMessageUtil.getMessage(I18nStringConstant.CONTRACT_ORDER));
        itemPoJo.setValue(0);
        itemPoJo.setAttr(XbbRefTypeEnum.CONTRACT.getAlias());
        itemPoJoList.add(itemPoJo);

        ItemPoJo otherItemPoJo = new ItemPoJo();
        otherItemPoJo.setText(I18nMessageUtil.getMessage(CommonConstant.PURCHASE));
        otherItemPoJo.setValue(1);
        otherItemPoJo.setAttr(XbbRefTypeEnum.PURCHASE.getAlias());
        itemPoJoList.add(otherItemPoJo);
        rangeScreenPojo.setItems(itemPoJoList);
        List<SpecialListFieldPojo> fieldList = new ArrayList<>();
        fieldList.add(rangeScreenPojo);

        SpecialListFilterVO specialListFilterVO = new SpecialListFilterVO();
        for (ContractCompareEnum contractCompareEnum : ContractCompareEnum.values()) {
            if (Objects.equals(contractCompareEnum, ContractCompareEnum.FORM_TYPE) || Objects.equals(contractCompareEnum, ContractCompareEnum.COMPARE_STATUS)) {
                continue;
            }
            SpecialListFieldPojo contractComparePojo = new SpecialListFieldPojo();
            contractComparePojo.setAttr(contractCompareEnum.getSaasAttr());
            contractComparePojo.setAttrName(contractCompareEnum.getAttrName());
            if (Objects.equals(contractCompareEnum.getAttr(), ContractCompareEnum.ADD_TIME.getAttr())) {
                contractComparePojo.setFieldType(FieldTypeEnum.ADDTIME.getType());
            } else if (Objects.equals(contractCompareEnum.getAttr(), ContractCompareEnum.CREATOR_ID.getAttr())) {
                contractComparePojo.setFieldType(FieldTypeEnum.CREATORID.getType());
            } else {
                contractComparePojo.setFieldType(FieldTypeEnum.TEXT.getType());
                contractComparePojo.setPlaceholder(I18nMessageUtil.getMessage(I18nStringConstant.SELECT_OR_ENTER_SEARCH));
            }
            contractComparePojo.setMultiple(0);
            fieldList.add(contractComparePojo);
        }
        specialListFilterVO.setFieldList(fieldList);
        return specialListFilterVO;
    }
}
